#include "dock.h"
#include <QWebFrame>

Dock::Dock(QWidget *parent) : QWidget(parent)
{
    setMinimumWidth(250);

    QGridLayout* searchLayout = new QGridLayout;
    searchButton = new QPushButton("Search", this);
    searchEdit = new QLineEdit(this);
    searchLayout->addWidget(searchButton, 0, 1);
    searchLayout->addWidget(searchEdit,0 , 0);
    filterLabel = new QLabel("Filter: ", this);
    filterEdit = new QLineEdit(this);
    searchLayout->addWidget(filterLabel, 1, 0);
    searchLayout->addWidget(filterEdit, 1, 1);

    QVBoxLayout* layout = new QVBoxLayout;
    layout->addLayout(searchLayout);
    layout->addWidget(VideoPlayer::get(), 0, Qt::AlignBottom);
    setLayout(layout);

    QObject::connect(filterEdit, SIGNAL(textChanged(QString)), this, SLOT(searchAltered(QString)));
    QObject::connect(searchButton, SIGNAL(clicked()), this, SLOT(performSearch()));
}

void Dock::searchAltered(QString word)
{
    qDebug("search is altered");
    emit filterNeedsUpdate(word);
}

void Dock::performSearch()
{
    NetworkCommunicator::instance()->search(searchEdit->text());
}

